package com.penghk.springbootdemo.aware;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class AwareService implements BeanNameAware , ResourceLoaderAware {

    private String name;

    private ResourceLoader resourceLoader;
    @Override
    public void setBeanName(String s) {
        name = s;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    public void output() throws IOException {
        System.out.println(" bean name : "+name);
        Resource resource = resourceLoader.getResource("classpath:static/test.txt");
        System.out.println("获取资源是　：　"+ IOUtils.toString(resource.getInputStream()));
    }




}
